﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebsiteClient.Models;

namespace WebsiteClient.DB
{
    public class EventDB
    {
        static ApplicationDbContext db = new ApplicationDbContext();

        public void AddEvent(Event newEvent)
        {
            db.Events.Add(newEvent);
            db.SaveChanges();
            
        }

        public Event GetFirstEvent()
        {
            //return db.Event.FirstOrDefault();
            return null;
        }

        public void DeleteEvent(Event removedEvent)
        {
            //db.Event.Remove(removedEvent);
            db.SaveChanges();
        }

        public Event FindEventByTitle(string title)
        {
            var query = from e in db.Events select e;

            foreach (Event item in query)
            {
                if (item.Title == title)
                {
                    return item;
                }
            }
            return null;
        }

        public List<Event> FindAllEvents()
        {
            var query = from e in db.Events select e;
            List<Event> list = new List<Event>();

            foreach (var item in query)
            {
                list.Add(item);
            }

            return list;
        }

        internal List<Event> GetEventsById(string id)
        {
            var query = from e in db.Events select e;
            List<Event> list = new List<Event>();

            foreach (var item in query)
            {
                if (item.ApplicationUser_Id == id)
                {
                    list.Add(item);
                }

            }
            return list;
        }
    }
}
